//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------
/*
	Logger -	log class for write html logs with color highlighting.
				message template: "date - time - [thread ID] - message"
*/

#pragma once

#include "Base/Include/BaseObject.h"

namespace Engine
{
namespace Base
{

	//
	// Logger
	//

	class Logger : public BaseObject
	{
	// variables
	private:
		WFilePtr			_logFile;
		Mutex				_lockLog;
		string				_crashFileName;
		string				_buffer;

		static Logger *		_instance;


	// methods
	public:
		Logger (const EngineSubSystemsRef ess);
		~Logger ();

		// Log File //
		bool Open (uni_c_string name, bool unique);
		void Close ();

		void Write (uni_c_string msg, ELog::type type, uni_c_string file, int line);


		// Crash File //
		bool CreateCrashFile (uni_c_string name);	// on start application
		bool CloseCrashFile ();								// on stop application

		bool ReadCrashFile (uni_c_string name, OUT bool &wasCrashed, OUT Date &time) const;


		// Utils //
		void SendAnEmail ();

		static Logger * GetInstance ()		{ return _instance; }


	private:
		static void _GetDate (INOUT string &str);
		static void _GetDateForFName (INOUT string &str);
		static void _AddColor (INOUT string &str, ELog::type type);
		static char _GetPrefix (ELog::type type);

		static uni_c_string _GetFilePath (uni_c_string str, uint depth);
	};
	

}	// Base
}	// Engine
